<?php

use yii\db\Migration;

class m210222_083203_addon_flow_status extends Migration
{
    public function up()
    {
        /* 取消外键约束 */
        $this->execute('SET foreign_key_checks = 0');
        
        /* 创建表 */
        $this->createTable('{{%addon_flow_status}}', [
            'serial' => "int(11) NOT NULL AUTO_INCREMENT",
            'id' => "varchar(32) NOT NULL",
            'merchant_id' => "int(11) NULL DEFAULT '0'",
            'workflow_id' => "varchar(32) NOT NULL",
            'label' => "varchar(64) NULL",
            'sort' => "int(11) NULL",
            'type' => "int(1) NULL DEFAULT '0' COMMENT '0:不审核,1:指定人员 2:指定角色'",
            'audit_id' => "int(11) NULL DEFAULT '0' COMMENT '用户ID'",
            'role_id' => "int(11) NULL DEFAULT '0' COMMENT '角色ID'",
            'status' => "int(4) NULL DEFAULT '1'",
            'created_at' => "int(10) NULL",
            'updated_at' => "int(10) NULL",
            'PRIMARY KEY (`serial`)'
        ], "ENGINE=InnoDB DEFAULT CHARSET=utf8");
        
        /* 索引设置 */
        $this->createIndex('workflow_id','{{%addon_flow_status}}','workflow_id',0);
        
        
        /* 表数据 */
        
        /* 设置外键约束 */
        $this->execute('SET foreign_key_checks = 1;');
    }

    public function down()
    {
        $this->execute('SET foreign_key_checks = 0');
        /* 删除表 */
        $this->dropTable('{{%addon_flow_status}}');
        $this->execute('SET foreign_key_checks = 1;');
    }
}

